class Solution:
    def validPath(
        self,
        n: int,
        edges: list[list[int]],
        source: int,
        destination: int
    ) -> bool:
        if source == destination:
            return True

        way_exisit = False

        edges = [tuple(edge) for edge in edges]

        start_edges = [edge for edge in edges if source in edge]

        visited_vertex = {source}
        visited_edges = set(start_edges)

        queue = []

        for edge in start_edges:
            if source == edge[0]:
                queue.append(edge[1])
            else:
                queue.append(edge[0])

        while queue:
            current_vertex = queue.pop(0)

            if current_vertex in visited_vertex:
                continue

            if current_vertex == destination:
                way_exisit = True
                break

            current_edges = [
                edge for edge in edges
                if current_vertex in edge and edge not in visited_edges
            ]

            for edge in current_edges:
                if edge not in visited_edges:
                    if current_vertex == edge[0]:
                        queue.append(edge[1])
                    else:
                        queue.append(edge[0])

            visited_edges.update(current_edges)
            visited_vertex.add(current_vertex)

        return way_exisit
